#!/bin/bash  

# 获取当前脚本所在的目录  
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")  

# 目标目录  
TARGET_DIR="$SCRIPT_DIR/../libreOffice/"  

# 检查目标目录是否存在  
if [ ! -d "$TARGET_DIR" ]; then  
  echo "Error: Target directory $TARGET_DIR does not exist."  
  exit 1  
fi  

# 切换到目标目录  
cd "$TARGET_DIR"LibreOffice*/RPMS || exit  

# 执行rpm命令  
echo "Installing RPMs..."  
sudo rpm -Uvh --force --nodeps *.rpm  

# 检查安装是否成功  
if [ $? -ne 0 ]; then  
  echo "Error: RPM installation failed."  
  exit 1  
fi  

# 切换到/opt/libreoffice*目录  
OPT_DIR="/opt/libreoffice"  
cd "$OPT_DIR"*/ || exit  

# 列出目录内容并检查是否存在特定文件  
FILES=("CREDITS.fodt" "LICENSE" "program" "readmes" "share")  
FOUND=true  

for FILE in "${FILES[@]}"; do  
  if [ ! -e "$FILE" ]; then  
    FOUND=false  
    break  
  fi  
done  

# 判断是否所有文件都存在  
if [ "$FOUND" = true ]; then  
  echo "libreOffice安装成功"  

else  
  echo "Error: Some required files are missing in $OPT_DIR."  
  ls -l  
  exit 1  
fi